package middle;

public class Solution_62 {
//    private int count = 0;
    /*public int uniquePaths(int m, int n) {
        if (m == 1 && n == 1) {
            return 1;
        } else if (m == 1 && n > 1) {
            return uniquePaths(m, n - 1);
        } else if (m > 1 && n == 1) {
            return uniquePaths(m - 1, n);
        }
        return uniquePaths(m - 1, n) + uniquePaths(m, n - 1);
    }*/

    public int uniquePaths(int m, int n) {
        int[][] counts = new int[m][n];
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (i == 0 || j == 0) {
                    counts[i][j] = 1;
                } else {
                    counts[i][j] = counts[i - 1][j] + counts[i][j - 1];
                }
            }
        }
        return counts[m - 1][n - 1];
    }

    public static void main(String[] args) {
        Solution_62 model = new Solution_62();
        System.out.println(model.uniquePaths(3, 7));
        System.out.println(model.uniquePaths(3, 2));
        System.out.println(model.uniquePaths(7, 3));
        System.out.println(model.uniquePaths(3, 3));
        System.out.println(model.uniquePaths(51, 9));
    }
}
